/**
  ******************************************************************************
  * @file    Template/main.c
  * @author  MCD Application Team
  * @version V1.0.0
  * @date    20-September-2013
  * @brief   Main program body
  ******************************************************************************
  * @attention
  *
  * <h2><center>&copy; COPYRIGHT 2013 STMicroelectronics</center></h2>
  *
  * Licensed under MCD-ST Liberty SW License Agreement V2, (the "License");
  * You may not use this file except in compliance with the License.
  * You may obtain a copy of the License at:
  *
  *        http://www.st.com/software_license_agreement_liberty_v2
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  ******************************************************************************
  */

/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stm32f4xx_it.h"
#include "system_clock.h"


/* Fwk */
#include "fsl_os_abstraction.h"
#include "MemManager.h"
#include "TimersManager.h"
//#include "RNG_Interface.h"
#include "Messaging.h"
//#include "Flash_Adapter.h"
//#include "SecLib.h"
#include "Panic.h"
#include "LED.h"
#include "Keyboard.h"

#include "app.h"


/** @addtogroup Template
  * @{
  */

/* Private typedef -----------------------------------------------------------*/

/* Private define ------------------------------------------------------------*/

/* Private macro -------------------------------------------------------------*/
/* Private variables prototypes ----------------------------------------------*/

/* Private variables ---------------------------------------------------------*/
uint32_t TimingDelay = 0;

/* Private function prototypes -----------------------------------------------*/
void main_task(uint32_t param);
void hardware_init(void);

/* Private functions ---------------------------------------------------------*/
static void Delay(__IO uint32_t nTime);

/**
  * @brief   Main program
  * @param  None
  * @retval None
  */
void main_task(uint32_t param)
{
    static bool_t platformInitialized = FALSE;

    if (FALSE == platformInitialized)
    {
        platformInitialized = TRUE;
        (void)MEM_Init();
        TMR_Init();
        LED_Init();
        Led3Flashing();
        //KBD_Init((void*)0);
        KBD_Init(App_KeyboardCallBack);
    }
    
}


void hardware_init(void)
{
#if _SYSTEM_TICK_ENABLE
    if (SysTick_Config(SystemCoreClock / 1000))
    {
        /* Capture error */
        while (1);
    }
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0/*NVIC_PriorityGroup_4*/);
#endif    
    SetSysClock();
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
    STM_EVAL_PBInit(BUTTON_USER, BUTTON_MODE_GPIO);
    STM_EVAL_PBGetState(BUTTON_USER);
//    STM_EVAL_LEDInit(LED3);
//    STM_EVAL_LEDInit(LED4);
    STM_EVAL_COMInit(COM1, 115200);

    //Delay(100);
    printf("This is a Demo!!!\r\n");
    printf("Message Mechanism Test!!!\r\n");
}

/**
  * @brief  Inserts a delay time.
  * @param  nTime: specifies the delay time length, in milliseconds.
  * @retval None
  */
void Delay(__IO uint32_t nTime)
{
    TimingDelay = nTime;

    while(TimingDelay != 0);
}

/**
  * @brief  Decrements the TimingDelay variable.
  * @param  None
  * @retval None
  */
void TimingDelay_Decrement(void)
{
    if (TimingDelay != 0)
    {
        TimingDelay--;
    }
}


#ifdef  USE_FULL_ASSERT

/**
  * @brief  Reports the name of the source file and the source line number
  *         where the assert_param error has occurred.
  * @param  file: pointer to the source file name
  * @param  line: assert_param error line source number
  * @retval None
  */
void assert_failed(uint8_t* file, uint32_t line)
{
  /* User can add his own implementation to report the file name and line number,
     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  /* Infinite loop */
  while (1)
  {
    
  }
}
#endif

/**
  * @}
  */


/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
